Copyright: Copyright © LVDI Software


Contents
  DBExport Component V 2.5

       Properties	 Methods        Events	       Technical support      Installation

Unit

DBExport

Description

The component TDBExport enables you to export any table or query results in a professional way.
You can define formats using a wizard, choosing the type of file you want (variable, fixed, Paradox, DBase, Html ...) the separator character, the fields you want, the ordering of the fields, and many other setttings.

The two mandatory properties are the DataSet  (your table or query results) and the IniFile (the file that will hold the user settings).

After initializing this two properties (either using the object inspector or directly in your code), you can call either the method execute
to allow the user export the tables or queries interactively; or call the method BatchExport to do batch exporting.

Use the property ExportCaption if you want to change the default caption, the property ExportFile enables you to initialize the name of the resulting file, if you provide a help file set the HelpId to point to the help topic.


Properties

DataSet
ExportCaption
IniFile
ExportFile
LoadLastSetting

HelpId

MultiTable
OtherFields

QuitAfterExport

ShowProgress
ShowSummary


Technical Support

You can contact us directly through these :

Internet         : infos@lvdisoft.com

Compuserve : 100733,1402 or lvdi

Web site       : http://www.lvdisoft.com

Tel	        : +33 6 07 89 26 57

Fax	        : +33 1 46 63 42 31

Address       : LVDI Software 67, rue Charles Frerot 94250 Paris-Gentilly France


DataSet
Property DataSet

Applies to

TDBExport component

Declaration

property DataSet : TDataSet;

Description

Set this property to the name of the dataset that contains the data that will be exported, it will either be a TTable or a TQuery. The available datasets are listed in the drop down combo box for ease of use.

Example

  DBExportDialog1.DataSet := MyTable;

  DBExportDialog1.IniFile := 'eSettings.ini'

  DBExportDialog1.execute;


ExportCaption
Property ExportCaption

Applies to

TDBExport component

Declaration

property ExportCaption : string;

Default

"Export Data"

Description

Set this property to display a caption (window title) that suites your needs.

Example

  DBExportDialog1.ExportCaption := 'Export customer data';


IniFile
Property IniFile

Applies to

TDBExport component

Declaration

property DataSet : string;

Description

Set this property to the name of the IniFile that will contain the settings that the user will save. You better have different inifiles for each dataset to avoid mixing things.

Don't forget that you prepare a setting for a known dataset, this setting will contain field names, if you try to apply that setting to another dataset (that have different field names) you will get an error message :'This setting is incompatible with the current table (customer.db)'.

You can have one inifile storing settings for different datasets but you better give a significant  name, like 'CustomerSetting' for example.

Example

  DBExportDialog1.DataSet := MyTable;

  DBExportDialog1.IniFile := 'eSettings.ini'

  DBExportDialog1.execute;


ExportFile
Property ExportFile

Applies to

TDBExport component

Declaration

property ExportFile : string;

Default

""

Description

Set this property to initialize the edit box file name. If you don't set this property the edit box will be empty (if it's the first export ) or will hold the last used filename.

Example

  DBExportDialog1.ExportFile := 'c:\tmp|export.txt';


HelpId
Property HelpId

Applies to

TDBExport component

Declaration

property HelpId : integer

Default

0

Description

If you provide a help file you must set this property to point to your help file topic.number.

Leave it to zero if you don't provide a help file.

Example

  DBExportDialog1.HelpId := 133;


FilterField

Event FilterField

Applies to

TDBImport component

Declaration

property  FilterField: TFilterFieldEvent

TFilterFieldEvent = procedure(Sender: TObject; TableName, FieldName: string; var HideField : boolean) of object;

Description

This event happens before a field is shown to the user for export,this way you can hide some fields of a table

Use the TableName and FieldName to select the fields that you want to hide

Example

{In this example we don't want the users to export the field salary}

procedure TFrmDemo.DBExportDialog1FilterField(Sender: TObject; TableName,

  FieldName: string; var HideField: Boolean);

begin

If (UpperCase(TableName) = 'EMPLOYEE.DB') and (UpperCase(FieldName) = 'SALARY')

then HideField := True;

end;


LoadLastSetting

Property LoadLastSetting

Applies to

TDBExport component

Declaration

property LoadLastSetting: Boolean

Default

True

Description

When this property is True, the component will load automatically the last parameters used by the user to make an export, example :type of file to create, number of records, etc.

Example

  DBExportDialog1.LoadLastSetting := False;


Events

BeforeFieldExport

BeforeRecordExport

FilterField

FilterTable

FilterType


QuitAfterExport

Property QuitAfterExport

Applies to

TDBExport component

Declaration

property QuitAfterExport: Boolean

Default

False

Description

This property enables you to decide weather the wizard dialog will close itself after finishing the export.

By default it is set to 'False', i.e the dialog will stay until the user clicks on the button cancel.

Example

  DBExportDialog1.QuitAfterExport := True;


FilterTable

Event FilterTable

Applies to

TDBImport component

Declaration

property  FilterTable: TFilterTableEvent

TFilterTableEvent = procedure(Sender: TObject; TableName: string; var HideTable : boolean) of object;

Description

This event happens if you use MultiTable, before a table is shown to the user for export,this way you can hide some tables of the database

Use the TableName to select the Tables that you want to hide

Example

{In this example we don't want the users to export the table Employee.db}

rocedure TFrmDemo.DBExportDialog1FilterTable(Sender: TObject; TableName: string; var HideTable: Boolean);

begin

If (UpperCase(TableName) = 'EMPLOYEE.DB')

then HideTable := True;

end;


OtherFields

Property OtherFields

Applies to

TDBExport component

Declaration

property OtherFields : string;

Default

""

Description

Use this property to export other fields like calculated fields. the fields must be separated by a space.

Example

  DBExportDialog1.OtherFields := CalculatedFld1.FieldName + ' ' + CalculatedFld2.FieldName;


MultiTable

Property MultiTable

Applies to

TDBExport component

Declaration

property MultiTable: Boolean

Default

False

Description

When this property is True, the component allow the user to choose which table to export, you can filter out some tables using the property FilterTable. When exporting the results of a query, you must set this property to False.

The component will list all the tables found in the database pointed by the property DatabaseName of the TTable component.

Example

  DBExportDialog1.MultiTable := False;


Execute

Method Execute

Applies to

TDBExport component

Declaration

procedure execute;

Description

This method displays the export dialog box and returns when the user clicks on the close button.

Example

  DBExportDialog1.DataSet := MyTable;

  DBExportDialog1.IniFile := 'eSettings.ini'

  DBExportDialog1.execute;


ShowSummary

Property ShowSummary

Applies to

TDBExport component

Declaration

property ShowSummary: Boolean

Default

True

Description

This property enables you to display a dialog box at the end, that displays the number of records exported.

Set it to false when doing batch processing (no user interaction).

Example

  DBExportDialog1.ShowSummary := False;


BeforeFieldExport

Event BeforeFieldExport

Applies to

TDBImport component

Declaration

property  BeforeFieldExport: TBeforeFieldExportEvent

TBeforeFieldExportEvent = procedure(Sender: TObject; FieldName: string;

               FieldType : TFieldType; FieldSize : integer; var FieldValue: string) of object;

Description

This event happens before a value is exported to the text file, it could be useful in many cases

for example formatting a number with leading zeros and a sign.

Use the FieldName, FieldType, and FieldSize informations to choose the field you want to change

and use the FieldValue to assign a new value.

Example

{In this example we export to a text file and we need to insert a comma in a special field

Input : 50000 output : 500,00}

procedure TFrmExport.DBExportDialog1BeforeFieldExport(Sender: TObject;

  FieldName: String; FieldType: TFieldType; var FieldValue: OpenString);

begin

if  FieldName = 'Amount'  then

Insert ( ',', FieldValue, Length(FieldValue)-1);

end;


Installation

Getting Started

UNZIP the archive (eg: DBEXUS32.ZIP) to a directory temporally.

Create a directory to hold this component and any others that you will install in the future. (eg: C:\DELPHI\COMPONEN) It is easier to put new components in a separate directory since you can update them easily and if there is a new release of DELPHI it will not effect your component directory.

Installation of the HLP and KWF files.

·Exit DELPHI is you are running it, as you can not install the KWF file while delphi is running.

·Move or copy help file (e.g.: DBEXPORT.HLP) to your Delphi Bin directory (suggest C:\DELPHI\BIN), it only really needs to be somewhere on the path, but the DELPHI bin directory is a good place.

·Delphi has a program to add our help index to Delphis help index. What this does is allow you to search for both delphi commands and the commands and properties of the component you want to install. This program is called HELPINST and is found in the DELPHI\HELP sub directory. Copy the keyword file (DBEXPORT.KWF) to the delphi help directory.

·Change the current directory to the Delphi Help directory (e.g.: CD C:\DELPHI\HELP)

·Run the HELPINST program and load the DELPHI.HDX file from the DELPHI\BIN directory.

·Add the .KWF file (e.g.: DBEXPORT.KWF) to the list of indexs.

·Save the new index file and then exit the HelpInst program.

Installation of the DCU, DCR, FRM, AND TXT  files.

We next must add the component to the Delphi VCL Library.Copy the DCU, DCR, FRM, and TXT files to the directory that you made for the components. (e.g.:  C:\DELPHI\COMPONEN)

Load delphi and selected the Options menu Item, and then selected the Install Components option.

·Add the directory where you have installed the components to the search path directory. All components that get installed must be in this search path.

·Click the add button and then the browse button to navigate to the directory where you copied the .DCU file (e.g.: C:\DELPHI\COMPONEN)

·Select the List Files Of Type and select Unit File *.DCU, you should then see the DCU file that you copied to the directory. Select the file DBEXPORT.DCU and clic OK, you will be returned to the Install Components dialog box.

·Click on the OK button and the VCL library will be re-built.

·You will notice on your VCL Palette bar in DELPHI that there is now a new tab called DB DIALOGS, in side here will be an icon to represent the component you just installed.


BeforeRecordExport

Event BeforeRecordExport

Applies to

TDBImport component

Declaration

property  BeforeRecordExport: TBeforeRecordExportEvent

TBeforeRecordExportEvent = procedure(Sender: TObject; var currentRecord: string) of object;

Description

This event happens before the record  is exported to the text file, you can use this event to append a program generated field (not in the database), for example you can generate a key.

Example

{In this example we need to generate a key for each exported record,

we will assume that it is a variable length record with a comma as a field separator}

procedure TFrmExport.DBExportDialog1BeforeRecordExport(Sender: TObject; var currentRecord: String);

begin

Inc(Key);

currentRecord := currentRecord + ',' +IntToStr(Key);

end;


BatchExport

Method BatchExport

Applies to

TDBExport component

Declaration

procedure BatchExport (Setting : string);

Description

This method allows to do export in batch mode, with no user interaction.

The first and only parameter is the name of a previously designed setting.

Use exception handling to trap a possible error.

Example

  DBExportDialog1.DataSet := MyTable;

  DBExportDialog1.IniFile := 'eSettings.ini';

  DBExportDialog1.ShowProgress := False; {don't show anything}

  DBExportDialog1.ExportFile := 'c:\tmp\out.txt'; {do not forget to specify the output file!}

  DBExportDialog1.BatchExport('CustomersSetting');


Methods

Execute

BatchExport


ShowProgress

Property ShowProgress

Applies to

TDBExport component

Declaration

property ShowProgress: Boolean

Default

True

Description

This property enables you to show or hide the progress bar, this can be useful when doing batch processing (no user interaction), and also to speedup the export process.

Example

  DBExportDialog1.ShowProgress := False;


FilterType

Event FilterType

Applies to

TDBImport component

Declaration

property  FilterType: TFilterTypeEvent

TFilterType = procedure(Sender: TObject; TableName : string; FieldType : integer; var HideType : boolean) of object;

Description

This event happens before a type is shown to the user for export,this way you can hide some types,

For example you can disable the export to Paradox or DBase.

Use the TableName and FieldType to select the types that you want to hide.

The Type Variable cannot be disabled.

Example

{In this example we don't want the users to export to an Html page}

Type

 TTypeFormat    = (Variable, Fixed, HtmlTags, HtmlPage, Paradox, DBase);

procedure TFrmDemo.DBExportDialog1FilterType(Sender: TObject;

  TableName: string; FieldType: Integer; var HideType: Boolean);

begin

If (FieldType = HtmlPage) then HideType := True;

end;